<?php

namespace App\Models\Ddaman;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Models\common\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;

class RoleFunction extends Base
{
    use HasFactory;

    protected $table = "sy_role_function";

    const CREATED_AT = null;
    const UPDATED_AT = null;

    protected $fillable = [
        'role_id','function_id'
    ];


    public $rule = [
        'name' => 'required|string|between:2,100',
        'code' => 'required|unique:function',
    ];

    public $editRule = [
        'id' => 'required',
        'code' => 'required|unique:function',
        'name' => 'required|string|between:2,100',
    ];

    public $message = [
        'id.required' => '标识必须',
        'code.required' => '标识必须填写',
        'code.unique' => '标识不能重复',
        'name.required' => '名称必须填写',
    ];

    /*
     * 获取列表
     * */
    public function getList( $param = [] )
    {
        $limit = isset($param['limit']) ? $param['limit'] : 2;
        $where = [];

        if (isset($param['keywords']) && $param['keywords']){
            $keywords = trim($param['keywords']);
            $where[] = ['name','like',"%$keywords%"];
        }

        $field = array_merge(['id'],$this->fillable);
        $list = $this->where($where)->select($field)->paginate($limit);

        return $list;

    }



}
